Skip to content

Conversation

@isaacaflores2
Copy link

Description

Currently both confighttp and configgrpc set the client address based only one value RemoteAddress or the Peer information espectively. The PR adds the flexibility to the determine the client address based on the request metadata using a new config client_address_metadata_keys. If this value is empty or no valid IP is found in the metadata, the client address falls back to RemoteAddress or the Peer information to be backwards compatible

Link to tracking issue

Fixes #14186

Testing

  1. Updated unit test

  2. Created local collector which imports the attributes processor and ingested data

    Local Collector Details

    • Exported data using telemetrygen logs --otlp-insecure 1 --otlp-header x-forwarded-for=\"1.1.1.1\"
    • Collector config
      • Note this required adding github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocesso to components.go and other files in cmd/otelcorecol
    extensions:
      zpages:
        endpoint: localhost:55679
    
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: localhost:4317
            client_address_metadata_keys:
              - x-forwarded-for
          http:
            endpoint: localhost:4318
            client_address_metadata_keys:
              - x-forwarded-for
    
    processors:
      attributes/example:
        actions:
          - key: client.addr
            action: upsert
            from_context: client.address
      memory_limiter:
        # 75% of maximum memory up to 2G
        limit_mib: 1536
        # 25% of limit up to 2G
        spike_limit_mib: 512
        check_interval: 5s
    
    exporters:
      debug:
        verbosity: detailed
    
    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [attributes/example]
          exporters: [debug]
        metrics:
          receivers: [otlp]
          processors: [attributes/example]
          exporters: [debug]
        logs:
          receivers: [otlp]
          processors: [attributes/example]
          exporters: [debug]
    
      extensions: [zpages]
    
    • Verified the following collector debug output:

      2025-11-26T08:54:36.615-0800    info    ResourceLog #0
      Resource SchemaURL: https://opentelemetry.io/schemas/1.25.0
      Resource attributes:
           -> service.name: Str(telemetrygen)
      ScopeLogs #0
      ScopeLogs SchemaURL: 
      InstrumentationScope  
      LogRecord #0
      ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC
      Timestamp: 2025-11-26 16:54:36.585084 +0000 UTC
      SeverityText: Info
      SeverityNumber: Info(9)
      Body: Str(the message)
      Attributes:
           -> app: Str(server)
           -> client.addr: Str(1.1.1.1)
      Trace ID: 
      Span ID: 
      

Documentation

  • Updated the confighttp and configgrpc README.md files

@isaacaflores2 isaacaflores2 requested a review from a team as a code owner November 26, 2025 18:59
// getIP checks keys in order to get an IP address.
// Returns the first valid IP address found, otherwise
// returns nil.
func getIP(md metadata.MD, keys []string) *net.IPAddr {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for reviewer: I did not find a good common package for these helper funcs, so I opted to duplicate between confighttp and configgrpc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configurable list of metadata_keys that can be used to set client address

1 participant